package cn.sumpu.app.coolsk.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import cn.sumpu.toolkit.common.util.Common;

public class WebUtil {
	private static final String randChars = "ABCDEFGHIGKLMNOPQRSTUVWXYZ";
	private static Random random = new Random();
	public static int getNowMonth(String date) throws ParseException{
		if(!Common.empty(date)){
			Date d = Common.parseDate(date, "yyyy-MM-dd");
			Calendar cal = Calendar.getInstance();
			cal.setTime(d);
			int month = cal.get(Calendar.MONTH);
			return month+1;
		}
		return 0;
	}
	
	public static int getNextMonth(String date)throws ParseException{
		if(!Common.empty(date)){
			Date d = Common.parseDate(date, "yyyy-MM-dd");
			Calendar cal = Calendar.getInstance();
			cal.setTime(d);
			cal.add(Calendar.MONTH, 1);
			int month = cal.get(Calendar.MONTH);
			return month+1;
		}
		return 0;
	}
	
	public static String randTicketNum(String[] notInStr){
		char a = randChars.charAt(random.nextInt(26));
		int num = random.nextInt(10);
		String randStr = String.valueOf(a)+num;
		if(notInStr != null){
			for (String string : notInStr) {
				if(randStr.equals(string)){
					return randTicketNum(notInStr);
				}
			}
		}
		return randStr;
	}
	
	public static String addDate(String day, int x) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = format.parse(day);
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		if (date == null)
			return "";
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DAY_OF_MONTH, x);
		date = cal.getTime();
		cal = null;
		return format.format(date);
	}
	
	public static String stripTags(String html){
		  if(Common.empty(html)) return null;
		  String regEx="<.+?>"; //表示标签  
	        Pattern p=Pattern.compile(regEx);  
	        Matcher m=p.matcher(html);  
	        String s=m.replaceAll("");  
	        return s.replaceAll("&nbsp;", "");  
		 
	}
	
	public static void main(String[] args) {
//		System.out.println(randTicketNum(new String[]{"A1","B1","C1","D1","E1","F1","G1","H1","I1","J1","K1","L1","M1","N1","O1","P1","Q1","R1","S1","T1","U1","V1","W1"}));
		stripTags("<div><img src='aa.jpg'/>你知道我是谁吗？？？<都给我退下></div>");
	}

}
